<?php 
require('src/FacturaVenta.class.php');
$id   = (isset($_GET['id'])) ? $_GET['id']:0;
$cliId      = 0;
$cliNombre   = "";
$fveId      = $id;
$fveNro     = "";
        
if($id!=0){    
    $obj    = new FacturaVenta();
    $res    = $obj->getConsulta($id);
    if( $row = mysql_fetch_array( $res ) ){
        $cliId      = $row["cli_id"];
        $cliNombre  = $row["cli_rif"].' / '.$row["cli_razonsocial"];        
        $fveId      = $row["fve_id"];
	$odcNro     = $row["fve_nro"];
    }
}

?>
<script type="text/javascript">
var id 		= <?php echo $id; ?>;
var fveId       = <?php echo $fveId; ?>;
var ifvArray    = null;

$(document).ready(function(){

    jQuery("#formID").validationEngine();

    if(id==0){
        $("#cliente").autocomplete({
            source: "src/ordencompra.php?modo="+9,
            minLength: 2,
            select: function(event, ui) {
                     $("#cliId").val(ui.item.id);
            }
        });
    }else{
        $('#cliente').attr('disabled',true); 
    }
    
    $('#targetA').click(function() {
         if($('#formID').validationEngine('validate')){
            var cliId = $('#cliId').attr('value');
             //alert("CliId: " + cliId);
             $("#result-search").load('mOrdenFactura.php?id='+id+"&fveId="+fveId+"&cliId="+cliId,  {cliId: cliId}, function(){
                $.ajax({
                    url: 'src/ordenfactura.php?modo=5',
                    data: "submit=&cliId="+cliId+"&fveId="+fveId,
                    dataType: "json",
                    success: function(data) {
                         var pro = (typeof data.d) == 'string' ? eval('(' + data.d + ')') :  data;
                         $("#lblRif").html(pro[0].cirif);
                         $("#lblRazonS").html(pro[0].razonS);
                         $("#lblDireccion").html(pro[0].direcF);
                         $("#lblTelefono").html(pro[0].tlfOfi); 
                         if(id!=0){
                             ifvArray = pro[1];
                             agregarRow();
                         }
                         
                    }
                });
             });
            
         }
    });
});

</script>
<h1></h1>

<div class="z-form content-search" >
    <span class="title"> B&uacute;squeda </span>    
    <form id="formID">
        <div class="search">
            <label for="cliente"><span class="required">*</span>Cliente </label>        
            <input type="text" id="cliente" name="cliente" class="validate[required] text-input meddium" value="<?php echo $cliNombre ; ?>" />
            <span class="text-small">M&iacute;nimo 2 caracteres para la b&uacute;squeda.</span>
            <input type='hidden' id="cliId"  name="cliId" value='<?php echo $cliId; ?>'  />            
        </div>
        <a title="Aplicar B&uacute;squeda" id="targetA" > <img src="public/images/shared/search.gif"  align="middle"/> Buscar</a>            
    </form>
</div>

<div id="result-search">
</div>


<?php //include('includes/footer.php'); ?>
